<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增客服</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
</head>
<body>
<div style="width:80%;height:100%;margin:15px auto;overflow:auto;">
    <form class="layui-form" action="">
        <div class="layui-form-item" id="title_div">
            <label class="layui-form-label" >接待老师名称</label>
            <div class="layui-input-block">
                <input type="text" name="jdname" required  lay-verify="required" placeholder="请输入接待老师名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" id="message_div">
            <label class="layui-form-label" >密码</label>
            <div class="layui-input-block">
                <input type="password" name="jdpassword" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" id="message_phone">
            <label class="layui-form-label" >接待老师手机号(用于登录)</label>
            <div class="layui-input-block">
                <input type="text" name="jdphone" required  lay-verify="required|phone"  placeholder="请输入接待老师手机号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" >状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="启用" checked=""><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><span >启用</span></div>
                <input type="radio" name="status" value="0" title="禁用"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><span >禁用</span></div>
            </div>
        </div>

        <div class="layui-form-item" style="margin-top: 20px">
            <div class="layui-input-block">
                <button class="layui-btn" id="addWuye" lay-submit lay-filter="addWuye" >立即添加</button>
                <button type="reset" id="reset" class="layui-btn layui-btn-primary" >重置</button>
            </div>
        </div>
    </form>
</div>
</body>
<script src="/js/layui/layui.js"></script>
<script src="/js/layui/layui.all.js"></script>
<script src="/admin/js/token.js"></script>
<script>
    var $ = layui.jquery;

    layui.use(['form' , 'jquery' , 'upload'], function(){
        var form = layui.form;
        var upload = layui.upload;
        var type;   //轮播图类型（0：普通  1：链接）

        //添加操作
        form.on('submit(addWuye)',function(data){
            var kefuName = data.field.jdname;
            var password = data.field.jdpassword;
            var phone = data.field.jdphone;
            if (kefuName=='' || kefuName==null){
                layer.msg("请填写名称");
            }else if (password=='' || password==null){
                layer.msg("请填写密码");
            }else if (phone=='' || phone==null){
                layer.msg("请填写手机号");
            }else{
                var msgMovie = layer.load(1);
                data.field.jdname =  replaceReg(data.field.jdname);  // 替换
                data.field.jdpassword =  replaceReg(data.field.jdpassword);  // 替换
                data.field.jdphone =  replaceReg(data.field.jdphone);  // 替换
                $.ajax({
                    url:"/kefu/addKefu"
                    ,type:"POST"
                    ,contentType: 'application/json'
                    ,data:JSON.stringify(data.field)
                    ,success:function (data) {
                        if(data.code==200){
                            layer.close(layer.index);
                            layer.msg('添加成功');
                            setTimeout(function(){
                                window.location.reload();
                            },2000);
                        }else {
                            layer.msg(data.msg,{icon:2,time:2000})
                        }
                    }
                    ,error:function () {
                        console.log("ajax error");
                    }
                });
                layer.close(msgMovie);
            }
            return false;
        });

    });
</script>
</html>